package java8.lambda;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Random;

/**
 * @author dan shouyang
 */
public class Test {

   public static void main(String args[]){
//      Map testMap = new HashMap();
//      testMap.put("type", "2000");
//      System.out.println(testMap.get("type") instanceof String);
//      System.out.println(testMap.get("type") instanceof Integer);
//
//      testMap.computeIfPresent("type", (s, o) -> Integer.valueOf(o.toString()));
//      System.out.println(testMap.get("type") instanceof String);
//      System.out.println(testMap.get("type") instanceof Integer);

      Map testMap = new HashMap(){{
         put("parent", "123456789123");
      }};
      System.out.println(createOrgNo(testMap));
   }

   public static String createOrgNo(Map<String,Object> objectMap) {
      StringBuffer sb = new StringBuffer();
      if(Objects.nonNull(objectMap.get("parent"))){
         sb.append(objectMap.get("parent"));
      }
      return sb.append(getRandom(12)).substring(0,12);
   }

   /**
    * 生成指定位数的随机数
    */
   public static String getRandom(int length) {
      String value = "";
      Random random = new Random();
      for (int i = 0; i < length; i++) {
         value += String.valueOf(random.nextInt(10));
      }
      return value;
   }

}